package com.grwx.omc.entity;


import com.grwx.omc.constant.HttpStatus;
import com.grwx.omc.util.MessagesUtil;
import lombok.Data;
import org.apache.commons.lang.StringUtils;

@Data
public class ResponseData {

    private Integer code;

    private String msg;

    private Object data;

    public ResponseData(){}

    public ResponseData(int code, String msg) {
        this(code, msg, null);
    }

    public ResponseData(int code, String msg, Object data) {
        this.code = code;
        if(StringUtils.isNotEmpty(msg)) {
            String message = MessagesUtil.message(msg);
            this.msg =  message;
        } else {
            this.msg = msg;
        }
        this.data = data;
    }

    public static ResponseData success() {
        return ResponseData.success("操作成功！");
    }

    public static <T> ResponseData success(T data) {
        return new ResponseData(HttpStatus.SUCCESS, "操作成功！", data);
    }

    public static ResponseData success(String msg) {
        return new ResponseData(HttpStatus.SUCCESS, msg);
    }

    public static <T> ResponseData success(String msg, Object data) {
        return new ResponseData(HttpStatus.SUCCESS, msg, data);
    }

    public static ResponseData error(int code, String msg) {
        return new ResponseData(code, msg);
    }

    public static <T> ResponseData error(String msg, Object data) {
        return new ResponseData(HttpStatus.ERROR, msg, data);
    }

    public static ResponseData error(String msg) {
        return new ResponseData(HttpStatus.ERROR, msg);
    }

}
